#ifndef SC_TEXTURE_H
#define SC_TEXTURE_H
#include "sc_common_type.h"
BEGIN_K3D
struct STexture
{
public:
	friend class SGraphics;
	STexture();
	STexture(const char* filepath);
	~STexture();
	inline void sampler(float u,float v,float* r,float* g,float* b,float* a)
	{		
		if(m_pixels==NULL)return dTexture->sampler(u,v,r,g,b,a);
		if(u<0)u=0.0f;if(v<0)v=0.0f;
		if(u>1.0f)u=1.0f;if(v>1.0f)v=1.0f;
		int x=(int)(u*m_width);if(x==m_width)x--;
		int y=(int)(v*m_height);if(y==m_height)y--;
		int pdata=y*m_width*3+x*3;
		*r=m_pixels[pdata];
		*g=m_pixels[pdata+1];
		*b=m_pixels[pdata+2];
		int a12=0;a12++;
	}
	inline Color sampler(float u,float v)
	{
		if(m_pixels==NULL)return dTexture->sampler(u,v);
		if(u<0)u=0.0f;if(v<0)v=0.0f;
		if(u>1.0f)u=1.0f;if(v>1.0f)v=1.0f;
		int x=(int)(u*m_width);if(x==m_width)x--;
		int y=(int)(v*m_height);if(y==m_height)y--;
		int pdata=y*m_width*3+x*3;
		Color col;
		col.r=m_pixels[pdata];
		col.g=m_pixels[pdata+1];
		col.b=m_pixels[pdata+2];
		return col;
	}
	static void initDefault(const char* filepath);
	static STexture* getDefaultTex(){return dTexture;} 
private:
	static STexture* dTexture;
	HBITMAP m_hBitMap;
	BITMAP m_bitmap;
	HDC  m_hdc;
	int m_width;
	int m_height;
	int m_pitch;
	float* m_pixels;
};

END_K3D
#endif